home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 January / PCWorld_2007-01_cd.bin / v cisle / autoit / autoit-v3.2.0.1-setup.exe / Extras / AutoUpdateIt / AutoUpdateIt.au3
Encoding:
Windows Autorun File  |  2006-08-12  |  25.2 KB  |  639 lines

  1. ; =======================================================================
  2. ; AutoUpdateIt
  3. ; Original by Rob Saunders
  4. ; Modifications by JPM/strik3r0475
  5. ;
  6. ; Command Line Options:
  7. ;  - AutoUpdateIt.au3 [/release | /beta | /alpha] [/silent]
  8. ;    - /release   Download latest release
  9. ;    - /beta      Download latest beta
  10. ;    - /alpha     Download latest alpha
  11. ;    - /silent    Silently auto-install (resets all settings)
  12. ;
  13. ; History:
  14. ;  - 1.36 - Display current Beta (by strik3r0475)
  15. ;  - 1.35 - Fixed some display bugs
  16. ;  - 1.34 - Display Alpha release if available
  17. ;         - Command line parameters added /alpha to check for latest alpha
  18. ;  - 1.33 - Added Retry/Cancel msgbox when cannot connect to receive update file
  19. ;         - Added Progress bar for non-WinXP users
  20. ;  - 1.32 - Changed _CompareVersions again (integer comparison now)
  21. ;  - 1.31 - Rewrote _ClipPath again
  22. ;  - 1.30 - Rewrote a few UDFs (_CompareVersions, _ClipPath)
  23. ;         - Underscored all UDF names
  24. ;         - Removed a misplaced 'Then' screwing up command line options
  25. ;  - 1.21 - Stupid bug fixed (ignored version check for /beta command)
  26. ;         - CompareVersions function works properly now (was seeing 3.0.103.173 as newer than 3.1.0.1)
  27. ;  - 1.20 - Command line parameters added
  28. ;           - /release to check for latest public release
  29. ;           - /beta to check for latest beta
  30. ;           - /silent to install silently (you will lose your compiler and file settings)
  31. ;  - 1.11 - Starts the download when you press one of the download
  32. ;           buttons, resulting in pre-downloading while you choose
  33. ;           where to save the file
  34. ;         - Default name for Beta download includes full version string
  35. ;         - Deletes "au3_update.dat" from temp files after loading data
  36. ;  - 1.10 - Displays release date
  37. ;         - Changed layout of buttons / groups
  38. ;         - Slightly modified error message when server inaccessible
  39. ;  - 1.00 - "Release" / given a version number
  40. ;
  41. ; Forum Threads:
  42. ;  - http://www.autoitscript.com/forum/index.php?showtopic=7547&view=getnewpost
  43. ;  - http://www.autoitscript.com/forum/index.php?showtopic=12099&view=getnewpost
  44. ;
  45. ; =======================================================================
  46. #NoTrayIcon
  47. #Include <GUIConstants.au3>
  48. ; ========================================
  49. ; Predefine variables
  50. ; ========================================
  51. Global Const $s_Title = 'AutoUpdateIt'
  52. Global Const $s_Version = '1.36'
  53. Global Const $s_DatFile = 'http://www.autoitscript.com/autoit3/files/beta/update.dat'
  54. Global Const $s_DatFile_Local = @TempDir & '\au3_update.dat'
  55. Global Const $s_Au3UpReg = 'HKCU\Software\AutoIt v3\AutoUpdateIt'
  56. Global $i_DownSize, $s_DownPath, $s_DownTemp, $s_DownFolder
  57. Global $i_DatFileLoaded, $i_ValidAu3Path, $i_DnInitiated
  58. Global $s_AutoUpdate, $i_SilentInstall
  59. Dim $s_ReleaseVer, $s_ReleaseFile, $i_ReleaseSize, $i_ReleaseDate, $s_ReleasePage
  60. Dim $s_LatestBetaVer, $s_BetaFile, $i_BetaSize, $i_BetaDate, $s_BetaPage, $s_CurrBetaVer, $s_CurrBetaDate
  61. Dim $s_AlphaVer, $s_AlphaFile, $i_AlphaSize, $i_AlphaDate, $s_AlphaPage
  62. ; ========================================
  63. ; Read registry settings
  64. ; ========================================
  65. Global $s_DefDownDir = RegRead($s_Au3UpReg, 'DownloadDir')
  66. If @error Then
  67.     $s_DefDownDir = @DesktopDir
  68. EndIf
  69. Global $s_Au3Path = RegRead('HKLM\Software\AutoIt v3\AutoIt', 'InstallDir')
  70. If Not @error And FileExists($s_Au3Path & '\AutoIt3.exe') Then
  71.     $s_CurrVer = FileGetVersion($s_Au3Path & "\AutoIt3.exe")
  72.     $s_CurrDate = _FriendlyDate(FileGetTime($s_Au3Path & "\AutoIt3.exe", 0, 1))
  73. Else
  74.     $s_Au3Path = 'Installation not found'
  75.     $s_CurrVer = 'Unavailable'
  76. EndIf
  77. Global $s_BetaPath = RegRead('HKLM\Software\AutoIt v3\AutoIt', 'betaInstallDir')
  78. If Not @error And FileExists($s_BetaPath & '\AutoIt3.exe') Then
  79.     $s_CurrBetaVer = FileGetVersion($s_BetaPath & "\AutoIt3.exe")
  80.     $s_CurrBetaDate = _FriendlyDate(FileGetTime($s_BetaPath & "\AutoIt3.exe", 0, 1))
  81. Else
  82.     $s_BetaPath = 'Installation not found'
  83.     $s_CurrBetaVer = 'Unavailable'
  84. EndIf
  85. ; ========================================
  86. ; Check for command line parameters
  87. ; ========================================
  88. If _StringInArray($CmdLine, '/release') Or _StringInArray($CmdLine, '/beta') Or _StringInArray($CmdLine, '/alpha') Then
  89.     Opt('TrayIconHide', 0)
  90.     _Status('Checking for updates')
  91.     InetGet($s_DatFile, $s_DatFile_Local, 1)
  92.     If @InetGetBytesRead = -1 Then
  93.         _Status('Could not connect to site', 'Please check your connection and try again')
  94.         Sleep(4000)
  95.         Exit
  96.     EndIf
  97.     _LoadUpdateData()
  98.     If _StringInArray($CmdLine, '/release') And _CompareVersions($s_ReleaseVer, $s_CurrVer) Then
  99.         $s_AutoUpdate = $s_ReleaseFile
  100.         $s_DownTemp = @TempDir & '\autoit-v3-setup.exe'
  101.         $i_DownSize = $i_ReleaseSize
  102.     ElseIf _StringInArray($CmdLine, '/beta') And _CompareVersions($s_LatestBetaVer, $s_CurrVer) Then
  103.         $s_AutoUpdate = $s_BetaFile
  104.         $s_DownTemp = @TempDir & '\autoit-v' & $s_LatestBetaVer & '.exe'
  105.         $i_DownSize = $i_BetaSize
  106.     ElseIf _StringInArray($CmdLine, '/alpha') And _CompareVersions($s_AlphaVer, $s_CurrVer) Then
  107.         $s_AutoUpdate = $s_AlphaFile
  108.         $s_DownTemp = @TempDir & '\autoit-v' & $s_AlphaVer & '.exe'
  109.         $i_DownSize = $i_AlphaSize
  110.     EndIf
  111.     If $s_AutoUpdate Then
  112.         InetGet($s_AutoUpdate, $s_DownTemp, 1, 1)
  113.         $s_DownSize = Round($i_ReleaseSize / 1024) & ' KB'
  114.         While @InetGetActive
  115.             _Status('Downloading update', '', @InetGetBytesRead, $i_DownSize)
  116.         WEnd
  117.         _Status('Download Complete', 'Launching install')
  118.         Sleep(1000)
  119.         If _StringInArray($CmdLine, '/silent') Then
  120.             _Start('"' & $s_DownTemp & '" /S')
  121.         Else
  122.             _Start('"' & $s_DownTemp & '"')
  123.         EndIf
  124.     Else
  125.         _Status('No new versions available')
  126.         Sleep(1000)
  127.     EndIf
  128.     Exit
  129. EndIf
  130. ; ========================================
  131. ; GUI - Main Application
  132. ; ========================================
  133. Opt("GuiResizeMode", $GUI_DOCKALL)
  134. $gui_Main = GUICreate($s_Title, 350, 310 + 20)
  135. $me_Mn_Help = GUICtrlCreateMenu('&Help')
  136. $me_Mn_VisitSite = GUICtrlCreateMenuItem('&Visit the AutoIt3 Website', $me_Mn_Help)
  137. $me_Mn_About = GUICtrlCreateMenuItem('&About', $me_Mn_Help)
  138. GUICtrlCreateLabel('', 0, 0, 350, 2, $SS_SUNKEN)
  139. $gr_Instal_Details = GUICtrlCreateGroup('Current Installation Details', 5, 5, 340, 75)
  140. GUICtrlCreateLabel('Production Version: ' & $s_CurrVer, 15, 25, 145, 15)
  141. GUICtrlCreateLabel('Date: ' & $s_CurrDate, 15, 40, 145, 15)
  142. ;GUICtrlCreateLabel('Path: ' & $s_Au3Path, 15, 55, 145, 15)
  143. GUICtrlCreateLabel('Beta Version: ' & $s_CurrBetaVer, 190, 25, 145, 15)
  144. GUICtrlCreateLabel('Date: ' & $s_CurrBetaDate, 190, 40, 145, 15)
  145. ;GUICtrlCreateLabel('Path: ' & $s_BetaPath, 190, 55, 300, 15)
  146. $gr_Mn_Release = GUICtrlCreateGroup('Latest Public Release', 5, 85, 165, 60)
  147. $lb_Mn_ReleaseVer = GUICtrlCreateLabel('Version: Loading...', 15, 105, 145, 15)
  148. $lb_Mn_ReleaseDate = GUICtrlCreateLabel('Date: Loading...', 15, 120, 145, 15)
  149. $gr_Mn_Beta = GUICtrlCreateGroup('Latest Beta', 180, 85, 165, 60)
  150. $lb_Mn_BetaVer = GUICtrlCreateLabel('Version: Loading...', 190, 105, 145, 15)
  151. $lb_Mn_BetaDate = GUICtrlCreateLabel('Date: Loading...', 190, 120, 145, 15)
  152. $gr_Mn_Alpha = GUICtrlCreateGroup('Latest Alpha', 180 + 175, 85, 165, 60)
  153. $lb_Mn_AlphaVer = GUICtrlCreateLabel('Version: Loading...', 190 + 175, 105, 145, 15)
  154. $lb_Mn_AlphaDate = GUICtrlCreateLabel('Date: Loading...', 190 + 175, 120, 145, 15)
  155. GUIStartGroup()
  156. $ra_Mn_DoneNotify = GUICtrlCreateRadio('&Notify when download complete', 5, 155, 340, 15)
  157. $ra_Mn_DoneRun = GUICtrlCreateRadio('&Autorun install when download complete', 5, 175, 340, 15)
  158. ; Check default done option
  159. If RegRead($s_Au3UpReg, 'DoneOption') = 'Run' Then
  160.     GUICtrlSetState($ra_Mn_DoneRun, $GUI_CHECKED)
  161. Else
  162.     GUICtrlSetState($ra_Mn_DoneNotify, $GUI_CHECKED)
  163. EndIf
  164. $bt_Mn_Close = GUICtrlCreateButton('&Close', 10, 275, 330, 25)
  165. ; ========================================
  166. ; Control Set - Download Buttons
  167. ; ========================================
  168. $bt_Mn_ReleaseDl = GUICtrlCreateButton('Download Public &Release', 5, 195, 165, 30)
  169. GUICtrlSetState(-1, $GUI_DISABLE)
  170. $lb_Mn_ReleaseSize = GUICtrlCreateLabel('Size: Loading...', 5, 230, 165, 15, $SS_CENTER)
  171. $lb_Mn_ReleasePage = GUICtrlCreateLabel('Visit Download Page', 5, 245, 165, 15, $SS_CENTER)
  172. GUICtrlSetState(-1, $GUI_DISABLE)
  173. GUICtrlSetFont(-1, 9, 400, 4)
  174. GUICtrlSetColor(-1, 0x0000ff)
  175. GUICtrlSetCursor(-1, 0)
  176. $bt_Mn_BetaDl = GUICtrlCreateButton('Download &Beta', 180, 195, 165, 30)
  177. GUICtrlSetState(-1, $GUI_DISABLE)
  178. $lb_Mn_BetaSize = GUICtrlCreateLabel('Size: Loading...', 180, 230, 165, 15, $SS_CENTER)
  179. $lb_Mn_BetaPage = GUICtrlCreateLabel('Visit Download Page', 180, 245, 165, 15, $SS_CENTER)
  180. GUICtrlSetState(-1, $GUI_DISABLE)
  181. GUICtrlSetFont(-1, 9, 400, 4)
  182. GUICtrlSetColor(-1, 0x0000ff)
  183. GUICtrlSetCursor(-1, 0)
  184. $bt_Mn_AlphaDl = GUICtrlCreateButton('Download &Alpha', 180 + 175, 195, 165, 30)
  185. GUICtrlSetState(-1, $GUI_DISABLE)
  186. $lb_Mn_AlphaSize = GUICtrlCreateLabel('Size: Loading...', 180 + 175, 230, 165, 15, $SS_CENTER)
  187. $lb_Mn_AlphaPage = GUICtrlCreateLabel('Visit Download Page', 180 + 175, 245, 165, 15, $SS_CENTER)
  188. GUICtrlSetState(-1, $GUI_DISABLE)
  189. GUICtrlSetFont(-1, 9, 400, 4)
  190. GUICtrlSetColor(-1, 0x0000ff)
  191. GUICtrlSetCursor(-1, 0)
  192. $a_DownButtons = StringSplit($bt_Mn_ReleaseDl & '.' & _
  193.         $lb_Mn_ReleaseSize & '.' & _
  194.         $lb_Mn_ReleasePage & '.' & _
  195.         $bt_Mn_BetaDl & '.' & _
  196.         $lb_Mn_BetaSize & '.' & _
  197.         $lb_Mn_BetaPage & '.' & _
  198.         $bt_Mn_AlphaDl & '.' & _
  199.         $lb_Mn_AlphaSize & '.' & _
  200.         $lb_Mn_AlphaPage, '.')
  201. ; ========================================
  202. ; Control Set - Download Display
  203. ; ========================================
  204. $lb_Mn_DwnToTtl = GUICtrlCreateLabel('Downloading to:', 5, 195, 290, 15, $SS_LEFTNOWORDWRAP)
  205. $lb_Mn_DwnToTxt = GUICtrlCreateLabel('', 5, 210, 290, 15, $SS_LEFTNOWORDWRAP)
  206. $pg_Mn_Progress = GUICtrlCreateProgress(5, 225, 340, 20)
  207. $lb_Mn_Progress = GUICtrlCreateLabel('', 5, 250, 290, 15)
  208. $bt_Mn_OpenFile = GUICtrlCreateButton('&Open', 105, 275, 75, 25)
  209. GUICtrlSetState(-1, $GUI_DISABLE)
  210. $bt_Mn_OpenFolder = GUICtrlCreateButton('Open &Folder', 185, 275, 75, 25)
  211. GUICtrlSetState(-1, $GUI_DISABLE)
  212. $a_DownDisplay = StringSplit($lb_Mn_DwnToTtl & '.' & _
  213.         $lb_Mn_DwnToTxt & '.' & _
  214.         $pg_Mn_Progress & '.' & _
  215.         $lb_Mn_Progress & '.' & _
  216.         $bt_Mn_OpenFile & '.' & _
  217.         $bt_Mn_OpenFolder, '.')
  218. _GuiCtrlGroupSetState($a_DownDisplay, $GUI_HIDE)
  219. ; ========================================
  220. ; GUI - About
  221. ; ========================================
  222. $gui_About = GUICreate('About', 300, 120, -1, -1, BitOR($WS_CAPTION, $WS_SYSMENU), -1, $gui_Main)
  223. GUICtrlCreateLabel($s_Title & ' v' & $s_Version & ' - The AutoIt3 Update Utility' & @LF & _
  224.         @LF & _
  225.         'This application is a utility for easily receiving the most ' & _
  226.         'recent public release or beta version of AutoIt3 available. ' & _
  227.         'It was written in AutoIt3 script by Rob Saunders.', 5, 5, 290, 75)
  228. $lb_Ab_VisitSite = GUICtrlCreateLabel('Visit the AutoIt Website', 5, 80, 145, 15)
  229. GUICtrlSetFont(-1, 9, 400, 4)
  230. GUICtrlSetColor(-1, 0x0000ff)
  231. GUICtrlSetCursor(-1, 0)
  232. GUICtrlSetTip(-1, 'http://www.autoitscript.com')
  233. $lb_Ab_ContactAuthor = GUICtrlCreateLabel('Contact Rob Saunders', 5, 100, 145, 15)
  234. GUICtrlSetFont(-1, 9, 400, 4)
  235. GUICtrlSetColor(-1, 0x0000ff)
  236. GUICtrlSetCursor(-1, 0)
  237. GUICtrlSetTip(-1, 'rksaunders@gmail.com')
  238. $bt_Ab_Close = GUICtrlCreateButton('&Close', 220, 90, 75, 25)
  239. ; ========================================
  240. ; Application start
  241. ; ========================================
  242. ; Show Main Window
  243. GUISetState(@SW_SHOW, $gui_Main)
  244. ; Download update data file
  245. InetGet($s_DatFile, $s_DatFile_Local, 1, 1)
  246. ; Harness GUI Events
  247. While 1
  248.     $a_GMsg = GUIGetMsg(1)
  249.     If Not @InetGetActive And Not $i_DatFileLoaded Then
  250.         If @InetGetBytesRead = -1 Then
  251.             $i_Res = MsgBox(5 + 16 + 8192, 'Error', 'Error connecting to server.' & @LF & _
  252.                     'Please verify the following:' & @LF & _
  253.                     ' - You can connect to the internet' & @LF & _
  254.                     ' - You can access the site http://www.AutoItScript.com' & @LF & _
  255.                     ' - Your firewall is not blocking internet access to this program')
  256.             If $i_Res = 4 Then
  257.                 InetGet($s_DatFile, $s_DatFile_Local, 1, 1)
  258.             Else
  259.                 Exit
  260.             EndIf
  261.         Else
  262.             _LoadUpdateData()
  263.             If $s_AlphaVer <> '' Then
  264.                 If _CompareVersions(StringTrimRight($s_AlphaVer, 1), $s_LatestBetaVer) > 0 Then
  265.                     $pos = WinGetPos($s_Title)
  266.                     WinMove($s_Title, "", $pos[0], $pos[1], $pos[2] + 175, $pos[3])
  267.                     GUICtrlSetPos($gr_Instal_Details, 5, 5, 340 + 175, 75)
  268.                     GUICtrlSetPos($bt_Mn_Close, 10, 275, 330 + 175, 25)
  269.                     GUICtrlSetPos($lb_Mn_DwnToTtl, 5, 195, 290 + 175, 15)
  270.                     GUICtrlSetPos($lb_Mn_DwnToTxt, 5, 210, 290 + 175, 15)
  271.                     GUICtrlSetPos($pg_Mn_Progress, 5, 225, 340 + 175, 20)
  272.                     GUICtrlSetPos($lb_Mn_Progress, 5, 250, 290 + 175, 15)
  273.                     GUICtrlSetPos($bt_Mn_OpenFile, 105 + 175, 275, 75, 25)
  274.                     GUICtrlSetPos($bt_Mn_OpenFolder, 185 + 175, 275, 75, 25)
  275.                 Else
  276.                     $s_AlphaVer = ''
  277.                 EndIf
  278.             EndIf
  279.             $i_ReleaseSizeKB = Round($i_ReleaseSize / 1024)
  280.             $i_BetaSizeKB = Round($i_BetaSize / 1024)
  281.             $i_AlphaSizeKB = Round($i_AlphaSize / 1024)
  282.             If _CompareVersions($s_ReleaseVer, $s_CurrVer) Then
  283.                 GUICtrlSetData($gr_Mn_Release, 'Latest Public Release *New*')
  284.                 GUICtrlSetColor($gr_Mn_Release, 0x0000ff)
  285.             EndIf
  286.             GUICtrlSetData($lb_Mn_ReleaseVer, 'Version: ' & $s_ReleaseVer)
  287.             If _CompareVersions($s_LatestBetaVer, $s_CurrBetaVer) Then
  288.                 GUICtrlSetData($gr_Mn_Beta, 'Latest Beta *New*')
  289.                 GUICtrlSetColor($gr_Mn_Beta, 0x0000ff)
  290.             EndIf
  291.             GUICtrlSetData($lb_Mn_BetaVer, 'Version: ' & $s_LatestBetaVer)
  292.             If _CompareVersions($s_AlphaVer, $s_CurrVer) Then
  293.                 GUICtrlSetData($gr_Mn_Alpha, 'Latest Alpha *New*')
  294.                 GUICtrlSetColor($gr_Mn_Alpha, 0x0000ff)
  295.             EndIf
  296.             GUICtrlSetData($lb_Mn_AlphaVer, 'Version: ' & $s_AlphaVer)
  297.             GUICtrlSetData($lb_Mn_ReleaseDate, 'Date: ' & _FriendlyDate($i_ReleaseDate))
  298.             GUICtrlSetData($lb_Mn_BetaDate, 'Date: ' & _FriendlyDate($i_BetaDate))
  299.             GUICtrlSetData($lb_Mn_AlphaDate, 'Date: ' & _FriendlyDate($i_AlphaDate))
  300.             GUICtrlSetData($lb_Mn_ReleaseSize, 'Size: ' & $i_ReleaseSizeKB & ' KB')
  301.             GUICtrlSetData($lb_Mn_BetaSize, 'Size: ' & $i_BetaSizeKB & ' KB')
  302.             GUICtrlSetData($lb_Mn_AlphaSize, 'Size: ' & $i_AlphaSizeKB & ' KB')
  303.             GUICtrlSetTip($lb_Mn_ReleasePage, $s_ReleasePage)
  304.             GUICtrlSetTip($lb_Mn_BetaPage, $s_BetaPage)
  305.             GUICtrlSetTip($lb_Mn_AlphaPage, $s_AlphaPage)
  306.             GUICtrlSetState($bt_Mn_ReleaseDl, $GUI_ENABLE)
  307.             GUICtrlSetState($bt_Mn_BetaDl, $GUI_ENABLE)
  308.             GUICtrlSetState($bt_Mn_AlphaDl, $GUI_ENABLE)
  309.             GUICtrlSetState($lb_Mn_ReleasePage, $GUI_ENABLE)
  310.             GUICtrlSetState($lb_Mn_BetaPage, $GUI_ENABLE)
  311.             GUICtrlSetState($lb_Mn_AlphaPage, $GUI_ENABLE)
  312.             $i_DatFileLoaded = 1
  313.         EndIf
  314.     EndIf
  315.     If $i_DnInitiated Then
  316.         If @InetGetActive Then
  317.             $i_DnPercent = Int(@InetGetBytesRead / $i_DownSize * 100)
  318.             $s_DnBytes = Round(@InetGetBytesRead / 1024) & ' KB'
  319.             $s_DnSize = Round($i_DownSize / 1024) & ' KB'
  320.             GUICtrlSetData($pg_Mn_Progress, $i_DnPercent)
  321.             GUICtrlSetData($lb_Mn_Progress, 'Download Progress: ' & $i_DnPercent & '% (' & $s_DnBytes & ' of ' & $s_DnSize & ')')
  322.         Else
  323.             GUICtrlSetData($pg_Mn_Progress, 100)
  324.             If Not FileMove($s_DownTemp, $s_DownPath, 1) Then
  325.                 MsgBox(16 + 8192, 'Error', 'Error moving file.')
  326.                 GUICtrlSetData($lb_Mn_Progress, 'Error')
  327.             Else
  328.                 If GUICtrlRead($ra_Mn_DoneRun) = $GUI_CHECKED Then
  329.                     _Start('"' & $s_DownPath & '"')
  330.                     Exit
  331.                 Else
  332.                     GUICtrlSetData($lb_Mn_Progress, 'Download Complete!')
  333.                     GUICtrlSetData($bt_Mn_Close, '&Close')
  334.                     GUICtrlSetState($bt_Mn_OpenFile, $GUI_ENABLE)
  335.                     GUICtrlSetState($bt_Mn_OpenFolder, $GUI_ENABLE)
  336.                     $i_Response = MsgBox(4 + 64 + 256 + 8192, $s_Title, 'Download complete!' & @LF & _
  337.                             'Would you like to run the installer now?')
  338.                     If $i_Response = 6 Then
  339.                         _Start('"' & $s_DownPath & '"')
  340.                         Exit
  341.                     EndIf
  342.                 EndIf
  343.             EndIf
  344.             $i_DnInitiated = 0
  345.         EndIf
  346.     EndIf
  347.     If $a_GMsg[1] = $gui_Main Then
  348.         Select
  349.             ; Radio buttons
  350.             Case $a_GMsg[0] = $ra_Mn_DoneRun
  351.                 RegWrite($s_Au3UpReg, 'DoneOption', 'REG_SZ', 'Run')
  352.             Case $a_GMsg[0] = $ra_Mn_DoneNotify
  353.                 RegWrite($s_Au3UpReg, 'DoneOption', 'REG_SZ', 'Notify')
  354.                 ; Download buttons
  355.             Case $a_GMsg[0] = $bt_Mn_ReleaseDl
  356.                 $tmp = StringInStr($s_ReleaseFile, '/', 0, -1)
  357.                 $s_DefFileName = StringTrimLeft($s_ReleaseFile, $tmp)
  358.                 $i_DownSize = $i_ReleaseSize
  359.                 _DownloadFile($s_ReleaseFile, 'autoit-v3-setup.exe')
  360.             Case $a_GMsg[0] = $bt_Mn_BetaDl
  361.                 $tmp = StringInStr($s_BetaFile, '/', 0, -1)
  362.                 $s_DefFileName = StringTrimLeft($s_BetaFile, $tmp)
  363.                 $i_DownSize = $i_BetaSize
  364.                 _DownloadFile($s_BetaFile, 'autoit-v' & $s_LatestBetaVer & '.exe')
  365.             Case $a_GMsg[0] = $bt_Mn_AlphaDl
  366.                 $tmp = StringInStr($s_AlphaFile, '/', 0, -1)
  367.                 $s_DefFileName = StringTrimLeft($s_AlphaFile, $tmp)
  368.                 $i_DownSize = $i_AlphaSize
  369.                 _DownloadFile($s_AlphaFile, 'autoit-v' & $s_AlphaVer & '.exe')
  370.                 ; Download page "hyperlinks"
  371.             Case $a_GMsg[0] = $lb_Mn_ReleasePage
  372.                 _Start($s_ReleasePage)
  373.             Case $a_GMsg[0] = $lb_Mn_BetaPage
  374.                 _Start($s_BetaPage)
  375.             Case $a_GMsg[0] = $lb_Mn_AlphaPage
  376.                 _Start($s_AlphaPage)
  377.                 ; Open buttons
  378.             Case $a_GMsg[0] = $bt_Mn_OpenFile
  379.                 _Start('"' & $s_DownPath & '"')
  380.                 Exit
  381.             Case $a_GMsg[0] = $bt_Mn_OpenFolder
  382.                 _Start('"' & EnvGet('windir') & '\explorer.exe" /select,"' & $s_DownPath & '"')
  383.                 Exit
  384.                 ; Menu items
  385.             Case $a_GMsg[0] = $me_Mn_VisitSite
  386.                 _Start('http://www.autoitscript.com')
  387.             Case $a_GMsg[0] = $me_Mn_About
  388.                 GUISetState(@SW_SHOW, $gui_About)
  389.                 ; Close buttons
  390.             Case $a_GMsg[0] = $bt_Mn_Close
  391.                 _CancelDownload()
  392.             Case $a_GMsg[0] = $GUI_EVENT_CLOSE
  393.                 _CancelDownload(1)
  394.         EndSelect
  395.     ElseIf $a_GMsg[1] = $gui_About Then
  396.         Select
  397.             Case $a_GMsg[0] = $lb_Ab_VisitSite
  398.                 _Start('http://www.autoitscript.com')
  399.             Case $a_GMsg[0] = $lb_Ab_ContactAuthor
  400.                 _Start('"mailto:rksaunders@gmail.com?Subject=AutoIt3 Update Utility"')
  401.             Case $a_GMsg[0] = $GUI_EVENT_CLOSE Or $a_GMsg[0] = $bt_Ab_Close
  402.                 GUISetState(@SW_HIDE, $gui_About)
  403.         EndSelect
  404.     EndIf
  405. WEnd
  406.  
  407.  
  408. ; ========================================
  409. ; Function Declarations
  410. ; ========================================
  411. ; App. specific functions
  412. Func _DownloadFile($s_DownUrl, $s_DownName)
  413.     $s_DownTemp = @TempDir & '\' & $s_DownName
  414.     InetGet($s_DownUrl, $s_DownTemp, 1, 1)
  415.     $s_DownPath = FileSaveDialog('Save As', $s_DefDownDir, 'Executables (*.exe)', 16, $s_DownName)
  416.     If Not @error Then
  417.         If Not (StringRight($s_DownPath, 4) = '.exe') Then
  418.             $s_DownPath = $s_DownPath & '.exe'
  419.         EndIf
  420.         $tmp = StringInStr($s_DownPath, '\', 0, -1)
  421.         $s_DownFolder = StringLeft($s_DownPath, $tmp)
  422.         RegWrite($s_Au3UpReg, 'DownloadDir', 'REG_SZ', $s_DownFolder)
  423.         GUICtrlSetData($lb_Mn_DwnToTxt, _ClipPath($s_DownPath, 55))
  424.         GUICtrlSetData($lb_Mn_Progress, 'Download Progress: Calculating...')
  425.         _GuiCtrlGroupSetState($a_DownButtons, $GUI_HIDE)
  426.         _GuiCtrlGroupSetState($a_DownButtons, $GUI_DISABLE)
  427.         _GuiCtrlGroupSetState($a_DownDisplay, $GUI_SHOW)
  428.         If $s_AlphaVer <> '' Then
  429.             GUICtrlSetPos($bt_Mn_Close, 265 + 175, 275, 75, 25)
  430.         Else
  431.             GUICtrlSetPos($bt_Mn_Close, 265, 275, 75, 25)
  432.         EndIf
  433.         GUICtrlSetData($bt_Mn_Close, 'Cancel')
  434.         $i_DnInitiated = 1
  435.     Else
  436.         InetGet('abort')
  437.         FileDelete($s_DownTemp)
  438.     EndIf
  439. EndFunc   ;==>_DownloadFile
  440.  
  441.  
  442. Func _CancelDownload($i_Flag = 0)
  443.     If $i_DnInitiated Then
  444.         $i_Response = MsgBox(4 + 64 + 256 + 8192, $s_Title, 'Resuming is not possible.' & @LF & _
  445.                 'Your download will be lost.' & @LF & _
  446.                 'Continue?')
  447.         If $i_Response = 6 Then
  448.             $i_DnInitiated = 0
  449.             InetGet('abort')
  450.             FileDelete($s_DownTemp)
  451.             If $i_Flag = 1 Then
  452.                 Exit
  453.             EndIf
  454.             _GuiCtrlGroupSetState($a_DownDisplay, $GUI_HIDE)
  455.             GUICtrlSetData($bt_Mn_Close, '&Close')
  456.             If $s_AlphaVer <> '' Then
  457.                 GUICtrlSetPos($bt_Mn_Close, 10, 275, 330 + 175, 25)
  458.             Else
  459.                 GUICtrlSetPos($bt_Mn_Close, 10, 275, 330, 25)
  460.             EndIf
  461.             GUICtrlSetData($pg_Mn_Progress, 0)
  462.             _GuiCtrlGroupSetState($a_DownButtons, $GUI_SHOW)
  463.             _GuiCtrlGroupSetState($a_DownButtons, $GUI_ENABLE)
  464.         EndIf
  465.     Else
  466.         Exit
  467.     EndIf
  468. EndFunc   ;==>_CancelDownload
  469.  
  470.  
  471. Func _LoadUpdateData()
  472.     Global $s_ReleaseVer, $s_ReleaseFile, $s_ReleasePage, $i_ReleaseSize, $i_ReleaseDate
  473.     Global $s_LatestBetaVer, $s_BetaFile, $s_BetaPage, $i_BetaSize, $i_BetaDate
  474.     Global $s_AlphaVer, $s_AlphaFile, $s_AlphaPage, $i_AlphaSize, $i_AlphaDate
  475.     $s_ReleaseVer = IniRead($s_DatFile_Local, 'AutoIt', 'version', 'Error reading file')
  476.     $s_ReleaseFile = IniRead($s_DatFile_Local, 'AutoIt', 'setup', '')
  477.     $s_ReleasePage = IniRead($s_DatFile_Local, 'AutoIt', 'index', 'http://www.autoitscript.com')
  478.     $i_ReleaseSize = IniRead($s_DatFile_Local, 'AutoIt', 'filesize', 0)
  479.     $i_ReleaseDate = IniRead($s_DatFile_Local, 'AutoIt', 'filetime', 0)
  480.     $s_LatestBetaVer = IniRead($s_DatFile_Local, 'AutoItBeta', 'version', 'Error reading file')
  481.     $s_BetaFile = IniRead($s_DatFile_Local, 'AutoItBeta', 'setup', '')
  482.     $s_BetaPage = IniRead($s_DatFile_Local, 'AutoItBeta', 'index', 'http://www.autoitscript.com')
  483.     $i_BetaSize = IniRead($s_DatFile_Local, 'AutoItBeta', 'filesize', 0)
  484.     $i_BetaDate = IniRead($s_DatFile_Local, 'AutoItBeta', 'filetime', 0)
  485.     $s_AlphaVer = IniRead($s_DatFile_Local, 'AutoItAlpha', 'version', '')
  486.     $s_AlphaFile = IniRead($s_DatFile_Local, 'AutoItAlpha', 'setup', '')
  487.     $s_AlphaPage = IniRead($s_DatFile_Local, 'AutoItAlpha', 'index', 'http://www.autoitscript.com')
  488.     $i_AlphaSize = IniRead($s_DatFile_Local, 'AutoItAlpha', 'filesize', 0)
  489.     $i_AlphaDate = IniRead($s_DatFile_Local, 'AutoItAlpha', 'filetime', 0)
  490.     FileDelete($s_DatFile_Local)
  491. EndFunc   ;==>_LoadUpdateData
  492.  
  493.  
  494. ; Utility functions
  495. Func _Start($s_StartPath)
  496.     If @OSTYPE = 'WIN32_NT' Then
  497.         $s_StartStr = @ComSpec & ' /c start "" '
  498.     Else
  499.         $s_StartStr = @ComSpec & ' /c start '
  500.     EndIf
  501.     Run($s_StartStr & $s_StartPath, '', @SW_HIDE)
  502. EndFunc   ;==>_Start
  503.  
  504.  
  505. Func _GuiCtrlGroupSetState(ByRef $a_GroupArray, $i_State)
  506.     For $i = 1 To $a_GroupArray[0]
  507.         GUICtrlSetState($a_GroupArray[$i], $i_State)
  508.     Next
  509. EndFunc   ;==>_GuiCtrlGroupSetState
  510.  
  511.  
  512. Func _ClipPath($s_Path, $i_ClipLen)
  513.     Local $i_Half, $s_Left, $s_Right
  514.     If StringLen($s_Path) > $i_ClipLen Then
  515.         $i_Half = Int($i_ClipLen / 2)
  516.         $s_Left = StringLeft($s_Path, $i_Half)
  517.         $s_Right = StringRight($s_Path, $i_Half)
  518.         $s_Path = $s_Left & '...' & $s_Right
  519.     EndIf
  520.     Return $s_Path
  521. EndFunc   ;==>_ClipPath
  522.  
  523.  
  524. Func _NumSuffix($i_Num)
  525.     Local $s_Num
  526.     Switch Int($i_Num)
  527.         Case 1, 21, 31
  528.             $s_Num = Int($i_Num) & 'st'
  529.         Case 2, 22
  530.             $s_Num = Int($i_Num) & 'nd'
  531.         Case 3, 23
  532.             $s_Num = Int($i_Num) & 'rd'
  533.         Case Else
  534.             $s_Num = Int($i_Num) & 'th'
  535.     EndSwitch
  536.     Return $s_Num
  537. EndFunc   ;==>_NumSuffix
  538.  
  539.  
  540. Func _FriendlyDate($s_Date)
  541.     Local $a_Months = StringSplit('January,February,March,April,May,June,July,August,September,October,November,December', ',')
  542.     Local $s_Year, $s_Month, $s_Day
  543.     $s_Year = StringLeft($s_Date, 4)
  544.     $s_Month = StringMid($s_Date, 5, 2)
  545.     $s_Month = $a_Months[Int(StringMid($s_Date, 5, 2)) ]
  546.     $s_Day = StringMid($s_Date, 7, 2)
  547.     $s_Day = _NumSuffix(StringMid($s_Date, 7, 2))
  548.     Return $s_Month & ' ' & $s_Day & ', ' & $s_Year
  549. EndFunc   ;==>_FriendlyDate
  550.  
  551.  
  552. Func _StringInArray($a_Array, $s_String)
  553.     Local $i_ArrayLen = UBound($a_Array) - 1
  554.     For $i = 0 To $i_ArrayLen
  555.         If $a_Array[$i] = $s_String Then
  556.             Return $i
  557.         EndIf
  558.     Next
  559.     SetError(1)
  560.     Return 0
  561. EndFunc   ;==>_StringInArray
  562.  
  563.  
  564. Func _CompareVersions($s_Vers1, $s_Vers2, $i_ReturnFlag = 0)
  565.     If $s_Vers1 = '' Then Return 0
  566.     Local $i, $i_Vers1, $i_Vers2, $i_Top
  567.     Local $a_Vers1 = StringSplit($s_Vers1, '.')
  568.     Local $a_Vers2 = StringSplit($s_Vers2, '.')
  569.     $i_Top = $a_Vers1[0]
  570.     If $a_Vers1[0] < $a_Vers2[0] Then
  571.         $i_Top = $a_Vers2[0]
  572.     EndIf
  573.     For $i = 1 To $i_Top
  574.         $i_Vers1 = 0
  575.         $i_Vers2 = 0
  576.         If $i <= $a_Vers1[0] Then
  577.             $i_Vers1 = Number($a_Vers1[$i])
  578.         EndIf
  579.         If $i <= $a_Vers2[0] Then
  580.             $i_Vers2 = Number($a_Vers2[$i])
  581.         EndIf
  582.         If $i_Vers1 > $i_Vers2 Then
  583.             $v_Return = 1
  584.             ExitLoop
  585.         ElseIf $i_Vers1 < $i_Vers2 Then
  586.             $v_Return = 0
  587.             ExitLoop
  588.         Else
  589.             $v_Return = -1
  590.         EndIf
  591.     Next
  592.     If $i_ReturnFlag Then
  593.         Select
  594.             Case $v_Return = -1
  595.                 SetError(1)
  596.                 Return 0
  597.             Case $v_Return = 1
  598.                 Return $s_Vers1
  599.             Case $v_Return = 0
  600.                 Return $s_Vers2
  601.         EndSelect
  602.     ElseIf $v_Return = -1 Then
  603.         SetError(1)
  604.         Return 0
  605.     Else
  606.         Return $v_Return
  607.     EndIf
  608. EndFunc   ;==>_CompareVersions
  609.  
  610.  
  611. Func _Status($s_MainText, $s_SubText = '', $i_BytesRead = -1, $i_DownSize = -1)
  612.     Global $i_ProgOn
  613.     Global $i_StatusPercent
  614.     If @OSVersion = "WIN_XP" Or @OSVersion = "WIN_2000" Or @OSVersion = "WIN_2003" Then
  615.         If $s_SubText <> '' Then
  616.             $s_SubText = @LF & $s_SubText
  617.         EndIf
  618.         If $i_BytesRead = -1 Then
  619.             TrayTip($s_Title, $s_MainText & $s_SubText, 10, 16)
  620.         Else
  621.             $s_DownStatus = Round($i_BytesRead / 1024) & ' of ' & Round($i_DownSize / 1024) & ' KB'
  622.             TrayTip($s_Title, $s_MainText & $s_SubText & @LF & $s_DownStatus, 10, 16)
  623.         EndIf
  624.     Else
  625.         If Not $i_ProgOn Then
  626.             ProgressOn($s_Title, $s_MainText, $s_SubText, -1, -1, 2 + 16)
  627.             $i_ProgOn = 1
  628.         Else
  629.             If $i_BytesRead = -1 Then
  630.                 ProgressSet($i_StatusPercent, $s_SubText, $s_MainText)
  631.             Else
  632.                 $s_DownStatus = 'Downloading ' & Round($i_BytesRead / 1024) & ' of ' & Round($i_DownSize / 1024) & ' KB'
  633.                 $i_StatusPercent = Round($i_BytesRead / $i_DownSize * 100)
  634.                 ProgressSet($i_StatusPercent, $s_DownStatus, $s_MainText)
  635.             EndIf
  636.         EndIf
  637.     EndIf
  638. EndFunc   ;==>_Status
  639.